'use client';

import React from 'react';
import { usePathname } from 'next/navigation';
import { useAuth } from './AuthProvider';
import AdminLayout from './AdminLayout';
import { Spin } from 'antd';

interface LayoutWrapperProps {
  children: React.ReactNode;
}

const LayoutWrapper: React.FC<LayoutWrapperProps> = ({ children }) => {
  const pathname = usePathname();
  const { loading, isAuthenticated } = useAuth();

  // 显示加载状态
  if (loading) {
    return (
      <div className="flex justify-center items-center min-h-screen">
        <Spin size="large" />
      </div>
    );
  }

  // 不需要布局的页面（如登录页）
  const noLayoutPages = ['/login'];
  const shouldUseLayout = !noLayoutPages.includes(pathname) && isAuthenticated;

  if (shouldUseLayout) {
    return <AdminLayout>{children}</AdminLayout>;
  }

  return <>{children}</>;
};

export default LayoutWrapper; 